package com.spring.sperapc.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.sperapc.web.model.Baby;
import com.spring.sperapc.web.model.Test;
import com.spring.sperapc.web.service.TestService;

/**
 * Created by wojunyu on 2015/7/24.
 */
@Controller
@RequestMapping(value = "/test")
@ApiIgnore
public class TestController {
    static Logger logger = Logger.getLogger(TestController.class.getName());
    @Resource
    private TestService testService;

    @RequestMapping(value = "/queryTest")
    @ResponseBody
    public Object queryTestList(String pageIndex,String pageSize){
        System.out.println("ok---->"+pageIndex+","+pageSize);
        Map<String, Object> datas = new HashMap<String, Object>();
        try{

            PageHelper.startPage(Integer.parseInt(pageIndex) + 1, Integer.parseInt(pageSize));
            List list = testService.queryTestList(null);
            PageInfo page = new PageInfo(list);
            datas.put("total", page.getTotal());
            datas.put("data", list);
            logger.info(datas);
            System.out.println("end "+page.getTotal()+","+list.size());
        }catch(Exception e){
            e.printStackTrace();
        }

        return datas;
    }
    
    @RequestMapping(value = "/myTest")
    @ResponseBody
    public Object myTest(@RequestBody List<Test> test) {
//    	System.out.println("---------->"+request.getSession().getId());
    	Map<String,Object> m = new HashMap<String,Object>();
    	for(Test t:test){
    		System.out.println("---------->"+ApplicationUtils.Object2String(t.getUsername())+","+
    						ApplicationUtils.Object2String(t.getPassword()));
    		
    		System.out.println("---------->"+t.getUsername()+","+
    				t.getPassword());
    	}
    	return m;
    }
    
    @RequestMapping(value = "/myTest2")
    @ResponseBody
    public Object myTest2(@RequestBody List<Map<String,Object>> test) {
//    	System.out.println("---------->"+request.getSession().getId());
    	Map<String,Object> m = new HashMap<String,Object>();
    	for(Map<String,Object> t:test){
    		System.out.println("---------->"+ApplicationUtils.Object2String(t.get("username"))+","+
    						ApplicationUtils.Object2String(t.get("password")));
    	}
    	return m;
    }

}
